package com.way.v2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 魏彪
 */
public class PayStrategy {
    interface PayKey {
        String ALI_PAY = "ALI_PAY";
        String JD_PAY = "JD_PAY";
        String WECHAT_PAY = "WECHAT_PAY";
        String UNION_PAY = "UNION_PAY";
        String DEFAULT_PAY = "DEFAULT_PAY";
    }

    private static final Map<String, Payment> STRATEGIES = new HashMap<>();

    static {
        STRATEGIES.put(PayKey.ALI_PAY, new AliPay());
        STRATEGIES.put(PayKey.JD_PAY, new JDPay());
        STRATEGIES.put(PayKey.WECHAT_PAY, new WechatPay());
        STRATEGIES.put(PayKey.UNION_PAY, new UnionPay());
    }

    public static Payment get(String payKey) {
        if (!STRATEGIES.containsKey(payKey)) {
            return STRATEGIES.get(PayKey.DEFAULT_PAY);
        }
        return STRATEGIES.get(payKey);
    }
}
